<script language="javascript" src="<?php echo JQUERYUI?>jquery.ui.mouse.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI?>jquery.ui.draggable.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI?>jquery.ui.position.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI?>jquery.ui.resizable.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI?>jquery.ui.dialog.min.js"></script>

<script>
	$(document).ready(function() {
		$( ".date" ).datepicker();
		$( ".date" ).datepicker( "option", "dateFormat", "dd-mm-yy");
		$( "#tgl_awal" ).change(function(){
			location.href = "<?php echo LAPBIAYA ?>list_result/"+$('#tgl_awal').val()+"/"+$('#tgl_akhir').val()+"/"+$('#filter_coa').val();
		});
		$( "#tgl_akhir" ).change(function(){
			location.href = "<?php echo LAPBIAYA ?>list_result/"+$('#tgl_awal').val()+"/"+$('#tgl_akhir').val()+"/"+$('#filter_coa').val();
		});
		$( "#filter_coa" ).change(function(){
			location.href = "<?php echo LAPBIAYA ?>list_result/"+$('#tgl_awal').val()+"/"+$('#tgl_akhir').val()+"/"+$('#filter_coa').val();
		});
		list_table = $('#list_laporan_biaya').dataTable({
			"bJQueryUI": true,
			"bFilter" : true,
			"aLengthMenu": [[10,25,50, 100, -1], [10,25,50,100, "Semua"]],
			"sPaginationType": "full_numbers",
			"oLanguage": {
				"sLengthMenu": "Menampilkan _MENU_ data",
				"sZeroRecords": "Belum ada data penerimaan kasir yang tersimpan",
				"sInfoFiltered": "(Hasil filter dari _MAX_ yang didapat)"
			}
		});
		$('#list_laporan_biaya_filter').hide();
		
		$( "#cetak_pdf" ).click(function(){
			tgl_awal = $( "#tgl_awal" ).val();
			tgl_akhir = $( "#tgl_akhir" ).val();
			jenis_biaya = $( "#filter_coa" ).val();
			location.href="<?php echo LAPBIAYA ?>cetak_pdf/"+tgl_awal+"/"+tgl_akhir+"/"+jenis_biaya;
		});
		$( "#cetak_excel" ).click(function(){
			tgl_awal = $( "#tgl_awal" ).val();
			tgl_akhir = $( "#tgl_akhir" ).val();
			jenis_biaya = $( "#filter_coa" ).val();
			location.href="<?php echo LAPBIAYA ?>cetak_excel/"+tgl_awal+"/"+tgl_akhir+"/"+jenis_biaya;
		});
	} );
</script>

<?php
$data['cur_parent_menu'] = 'laporan';
$data['cur_selected_menu'] = 'lapbiaya';
$this->load->view('template/menu_view', $data);
?>
<br/><br/><br/><br/><br/><br/>
<table width="100%">
	<tr>
		<?php
			$opt = array('SEMUA'=>'SEMUA');
			foreach($pil_coa as $item=>$value){
				$opt[$value['id']]=$value['nama_coa'];
			}
		?>
		<td align="center">
			COA : <?php echo form_dropdown('coa',$opt,$jenis_biaya,'id="filter_coa"') ?>
			Tgl Awal : <input type="text" class="date" id="tgl_awal" value="<?php echo $tgl_awal ?>"/>
			Tgl Akhir : <input type="text" class="date" id="tgl_akhir" value="<?php echo $tgl_akhir ?>"/>
		</td>
	</tr>
</table>
<br/>
Cetak : <span class="clicked" id="cetak_pdf">PDF</span> <span class="clicked" id="cetak_excel">Excel</span>
<br/>
<table id="list_laporan_biaya" width="100%" align="center" border="0">
	<thead>
		<tr>
			<th>No</th>
			<th>Tanggal Pembayaran</th>
			<th>No. SPJ</th>
			<th>No. Polisi</th>
			<th>Sopir</th>
			<th>Jurusan</th>
			<?php if ($jenis_biaya != 'SEMUA') { ?>
				<th>Jenis Biaya</th>
			<?php } ?>
			<th>Jumlah</th>
			<th>Cabang</th>
			<th>Kasir</th>
		</tr>
	</thead>
	<tbody>
		<?php
		$sum['jenis_biaya'] = '';
		for ($i = 0; $i < count($list_result); $i++) {
			?>
			<tr>
				<td><?php echo ($i+1) ?></td>
				<td><?php echo $setoran[$i]['tgl_pembayaran'] ?></td>
				<td><?php echo $list_result[$i]['NoSPJ'] ?></td>
				<td><?php echo $setoran[$i]['NoPol'] ?></td>
				<td><?php echo $setoran[$i]['driver'] ?></td>
				<td><?php echo $setoran[$i]['asal'] . "-" . $setoran[$i]['tujuan'] ?></td>

				<?php if ($jenis_biaya != 'SEMUA') { ?>
					<td><?php echo $setoran[$i]['nama_coa'] ?></td>
	<?php } ?>

				<td><?php $sum['jenis_biaya'] +=$list_result[$i]['jumlah'];
					echo $list_result[$i]['jumlah'] ?>
				</td>
				<td><?php echo $list_result[$i]['cabang'] ?></td>
				<td><?php echo $setoran[$i]['nama'] ?></td>
			</tr>
<?php } ?>
	</tbody>
</table>
<table>
	<tr>
		<td>Biaya Awal :</td>
		<td>Rp 
			<?php
				if(!empty($sum_asal['jumlah'])){
					echo number_format($sum_asal['jumlah'],0,'.',',');
				}else{
					echo number_format(0,0,'.',',');
				}
			?>
		</td>
	</tr>
	<tr>
		<td>Biaya Langsung :</td>
		<td>Rp 
			<?php
				if(!empty($sum_tujuan['jumlah'])){
					echo number_format($sum_tujuan['jumlah'],0,'.',',');
				}else{
					echo number_format(0,0,'.',',');
				}
			?>
		</td>
	</tr>

<?php if ($jenis_biaya != 'SEMUA'&&!empty($setoran[0])) { ?>
		<tr>
			<td><?php echo $setoran[0]['nama_coa'] ?> :</td>
			<td><?php echo $sum['jenis_biaya'] ?></td>
		</tr>
<?php } ?>

</table>